//
//  DestinationDetailTableViewCell.m
//  LT
//
//  Created by dllo on 16/5/24.
//  Copyright © 2016年 dllo. All rights reserved.
//

#import "DestinationDetailTableViewCell.h"
#import "UIImageView+WebCache.h"
@implementation DestinationDetailTableViewCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self createDiscount];
    }
    return self;
}

-(void)createDiscount{
    self.titleLabel = [[UILabel alloc]init];
    self.titleLabel.numberOfLines = 2;
    self.titleLabel.font = [UIFont systemFontOfSize:15];
    [self.contentView addSubview:self.titleLabel];
    
    self.photo = [[UIImageView alloc]init];
    [self.contentView addSubview:self.photo];
    
    self.priceLabel = [[UILabel alloc]init];
    self.priceLabel.textColor = [UIColor redColor];
    [self.priceLabel addSubview:self.priceLabel];
    
    self.priceoffLabel = [[UILabel alloc]init];
    self.priceoffLabel.font = [UIFont systemFontOfSize:13];
    self.priceoffLabel.textColor = [UIColor grayColor];
    [self.contentView addSubview:self.priceoffLabel];

}

-(void)layoutSubviews{
    [super layoutSubviews];
    self.photo.frame = CGRectMake(10* WIDTHCELL, 10* WIDTHCELL,( self.contentView.frame.size.width / 4)* WIDTHCELL, (self.contentView.frame.size.height - 20)* WIDTHCELL);
    self.titleLabel.frame = CGRectMake((self.photo.frame.size.width + 20)* WIDTHCELL, (self.photo.frame.origin.y)* WIDTHCELL, (self.contentView.frame.size.width - self.photo.frame.size.width - 20)* WIDTHCELL, (self.photo.frame.size.height / 2 + 10)* WIDTHCELL);
    self.priceoffLabel.frame = CGRectMake(self.titleLabel.frame.origin.x* WIDTHCELL, (self.contentView.frame.size.height - self.titleLabel.frame.size.height + 10)* WIDTHCELL, 80* WIDTHCELL, 20* WIDTHCELL);
    self.priceLabel.frame = CGRectMake(self.photo.frame.size.width * 3* WIDTHCELL, (self.priceoffLabel.frame.origin.y - 10)* WIDTHCELL, 80* WIDTHCELL, 30* WIDTHCELL);

}

-(void)setDismodel:(discountModel *)dismodel{
    _dismodel = dismodel;
    [self.photo sd_setImageWithURL:[NSURL URLWithString:_dismodel.photo]placeholderImage:[UIImage imageNamed:@"LETU"]];
    self.titleLabel.text = _dismodel.title;
    self.priceoffLabel.text = _dismodel.priceoff;
    
    NSRegularExpression *regular = [NSRegularExpression regularExpressionWithPattern:@"[a-zA-Z.<,>,/]" options:0 error:NULL];
    NSString *string = _dismodel.price;
    //什么意思?
    NSString *price = [regular stringByReplacingMatchesInString:string options:0 range:NSMakeRange(0, [string length]) withTemplate:@""];
    self.priceLabel.text = price;
}

- (void)awakeFromNib {
    // Initialization code
    
    
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
    // Configure the view for the selected state
    
    
    
}

@end
